<i><%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
	<!DOCTYPE html>
	<html>
<head>
<meta charset="UTF-8">
<title>Banner图 编辑页面</title>
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
<jsp:include page="../com/header.jsp"></jsp:include>
<script type="text/javascript" src="../../js/comm/editcomm.js"></script>
<script type="text/javascript">
	$(function() {
// 		getDataById(root + 'cms/banner/findBannerById',"#bannerTmpl","#bannerContent");
		$("#saveOrupdate").click(function() {
			if (!$('#bannerContent').find('#myImageShow').attr('src')) {
				myAlert("请上传图片");
				return;
			}
			if (!$('#bannerContent').find('#sort').val()) {
				myAlert("请填写排序值");
				return;
			}
			if ($("#type").val() == 5 || $("#type").val() == 6 ) {
				if ($("#intro").val() == null || $("#intro").val() == 0) {
					myAlert("简要文字说明不能为空");
					return;
				}
			}
			saveBanner(root + 'cms/banner/saveBanner','bannerList.jsp');
		});
		var tId = getUrlParam("id");
		if (!tId) {
			myAlert('id参数不能为空');
			return;
		}
		$.ajax({
			url : root + 'cms/banner/findBannerById',
			type : 'post',
			dataType : 'json',
			data : {
				modelId : tId
			},
			success : function(data) {
				console.log(data);
				var contentHtml = "";
				if (data.code == 1) {
					contentHtml = $('#bannerTmpl').render(data.object, {
						mydata : data
					});
					$('#bannerContent').html(contentHtml);
// 					判断显示哪一个
					if (data.object.type == 1) {
						$('#bannerContent').find('#pic').show();
						$('#bannerContent').find('#link').show();
						$('#bannerContent').find('#int').hide();
						$('#bannerContent').find('#int').val('');
					} else if (data.object.type == 5 || data.object.type == 6) {
						$('#bannerContent').find('#pic').show();
						$('#bannerContent').find('#link').show();
						$('#bannerContent').find('#int').show();
					}
				} else {
					contentHtml = $('#bannerTmpl').render("");
					$('#bannerContent').html(contentHtml);
				}
				
			}
		});
		//更改跳转类型
		$('#bannerContent').on('change', '#type', function() {
			if ($(this).val() == 1) {
				$('#bannerContent').find('#pic').show();
				$('#bannerContent').find('#link').show();
				$('#bannerContent').find('#int').hide();
				$('#bannerContent').find('#int').val('');
			} else if ($(this).val() == 5 || $(this).val() == 6) {
				$('#bannerContent').find('#pic').show();
				$('#bannerContent').find('#link').show();
				$('#bannerContent').find('#int').show();
			}
		});
		
		//上传图片
		$(document).on('change', '#uploadPhotoFile', function() {
			$('#uploadPhotoFile').fileupload({
				url : root+'cms/banner/photoUpload',
			    dataType: 'json',
			    done: function (e, data) {
			        console.log("fileupload1:"+data);
			        data = data.result;//替换掉原来的data
			        console.log("fileupload2:"+data.toString());
			        if (data) {
			            var ds = data.object.split(":");
			            if (ds[0] == 1) {
			            	//校验图片大小
							if(!((ds[2]==250 && ds[3]==640) || (ds[3]/ds[2]==2.56))){
								myAlert("请上传图片尺寸为640*250像素，<br>或图片尺寸比例为640:250");
								return;
							}
							//校验图片大小end
			            	imgUrl = ds[1];
			            	$("#picurl").val(ds[1]);
			                $("#myImageShow").attr('src', "../../" + ds[1]);
			                $("#myImageShow").attr('width', '100px');
			                $("#myImageShow").attr('height', '100px');
			            } else {
			                myAlert(ds[1]);
			            }
			        }
			    },
			    progressall: function (e, data) {
			        var progress = parseInt(data.loaded / data.total * 100, 10);
			        console.log("上传进度："+progress);
			    },
			    fail:function (e, data) {
			        console.log("fail..." + e + data);
			    },
			    start:function (e) {
			        console.log("start..." + e);
			    }
			});
		});
	});
</script>
</head>
<body>
	<section>
		<div>
			<div class="col-xs-12">
				<div class="box" style="height:900px">
					<div class="box-header">
						<br> <input type="button" value="确定" id="saveOrupdate"
							class="btn btn-success">
						<input type="button" onclick="backAction('bannerList.jsp');" class="btn btn-info" value="返回"/>
					</div>
					<form id="submit_form" class="form-horizontal">
						<div class="tab" id="bannerContent"></div>
					</form>
				</div>
			</div>
		</div>
	</section>
	<script type="text/x-jsrender" id="bannerTmpl">
			<fieldset> 
				<input type="hidden" id="tId" name="id" value="{{:id}}" />
	        	{{!--<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">图片：</label>
       				 <div class="col-md-3">
						<div class="upload_div">
                        	<img id="myImageShow" src="../../{{:imgUrl}}" width="100px" height="100px" />
                        	<input type="hidden" id="imgUrl" name="imgUrl" value="{{:imgUrl}}"/>
                        	<input type="file" id="uploadPhotoFile" name="photoFile" class="upload_file">
                        </div>
					</div>
      			</div>--}}
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">类型：</label>
       				 <div class="col-md-3">
						{{!--<input type="text" placeholder="请填写类型" class="form-control input-sm" data-rule="required;length[0~50]" id="type" name="type" value="{{:type}}" />--}}
						<select class="form-control input-sm" id="type" name="type" data-rule="required" >
                          <option  value="">请选择</option>
                          <option  value="1" {{if type=="1"}}selected{{/if}}>首页banner</option>
						  <option  value="5" {{if type=="5"}}selected{{/if}}>游学banner</option>
						  <option  value="6" {{if type=="6"}}selected{{/if}}>商城banner</option>
                        </select>
					</div>
      			</div>
				<div class="form-group"  id="pic">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">图片地址：</label>
       				 <div class="col-md-3">
						<div class="upload_div">
                        	<img id="myImageShow" src="../../{{:picurl}}" width="100px" height="100px" />
                        	<input type="hidden" id="picurl" name="picurl" value="{{:picurl}}"/>
                        	<input type="file" id="uploadPhotoFile" name="photoFile" class="upload_file">
                        </div>
					</div>
				</div>
				<div class="form-group" id="link">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">图片指向地址：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写图片指向地址" class="form-control input-sm" id="linkurl" name="linkurl" value="{{:linkurl}}" />
					</div>
      			</div>
				<div class="form-group" id="Sort">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">排序值：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写排序值" class="form-control input-sm" data-rule="required;length[0~50]" id="sort" name="sort" value="{{:sort}}" />
					</div>
      			</div>
				<div class="form-group" style="display:none;" id="int">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">简要文字说明：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写简要文字说明" class="form-control input-sm" data-rule="required" id="intro" name="intro" value="{{:intro}}" />
					</div>
      			</div>
			</fieldset>
	</script>
</body>
	</html></i>